<template>
  <div class="brand-view">
    <v-title :title="title" />
    <arrow />
    <loading :show="loading" />
    <list :list="list" />
    <pull-up
      :loading="loading"
      :busy="queryList.busy"
      :data-len="list.length"
      @loadMore="loadMore" />
  </div>
</template>

<script>
import Title from '@/components/Title'
import Arrow from '@/components/Arrow'
import Loading from '@/components/Loading'
import api from '@/api'
import base64 from '@/util/base64'
import PullUp from '@/components/PullUp'
import List from '@/views/product/components/list'

export default {
  name: 'BrandView',
  components: {
    'v-title': Title,
    Arrow,
    Loading,
    PullUp,
    List
  },
  data() {
    return {
      loading: false,
      list: [],
      queryList: {},
      title: ''
    }
  },
  methods: {
    loadMore() {
      setTimeout(() => {
        this.getList(true)
      }, 200)
    },
    getList(append = false) {
      if (this.queryList.busy === false) {
        this.queryList.page++
        this.loading = true
        this.queryList.busy = true
        api.Product.brandView({
          ...this.queryList,
          brand_id: this.$route.params.id
        }).then(response => {
          let { data } = response
          data = base64.parse(data)
          // brand name
          this.title = data.title
          if (data.list.length === 0) {
            this.queryList.busy = true
          } else {
            this.queryList.busy = false
            if (append) {
              this.list = this.list.concat(data.list)
            } else {
              this.list = data.list
            }
          }
        }).finally(() => {
          this.loading = false
        })
      }
    },
    init() {
      this.queryList = {
        page: 0,
        pageSize: 10,
        busy: false
      }
      this.list = []
    }
  },
  created () {
    this.init()
  },
  activated () {
    this.init()
    this.getList()
  },
  deactivated () {
    this.queryList.busy = true
  }
}
</script>

<style scoped lang="stylus">
.brand-view
  padding-top 45px
</style>
